//
//  ChangeRootViewTool.m
//  17LoanTemplate
//
//  Created by gynjobs on 2017/8/23.
//  Copyright © 2017年 cangming. All rights reserved.
//

#import "ChangeRootViewTool.h"
#import "AfterWebViewController.h"
#import "StarLoadingViewController.h"
#import "BaseCommondTabbarController.h"

@implementation ChangeRootViewTool
+ (instancetype)getInstance{
    static id instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance  = [[ChangeRootViewTool alloc]init];
    });
    return instance;
}
- (instancetype)init{
    self = [super init];
    if (self) {
    }
    return self;
}
-(void)GotoTheStarLoadingController{
    StarLoadingViewController* launchView = [[StarLoadingViewController alloc]init];
    UIApplication *application = [UIApplication sharedApplication];
    UIWindow *window = application.keyWindow;
    window.backgroundColor = [UIColor whiteColor];
    window.rootViewController = launchView;
}
-(void)GotoBefoteCheckController{
    BaseCommondTabbarController *baseTabbar = [[BaseCommondTabbarController alloc]init];
    baseTabbar.ViewControllersArray = [BaseCommondObject getTabbarImageData];
    UIApplication *application = [UIApplication sharedApplication];
    UIWindow *window = application.keyWindow;
    window.backgroundColor = [UIColor whiteColor];
    window.rootViewController = baseTabbar;
}
-(void)gotoRootAfterCheckController{
    BaseCommondTabbarController *tabbar = [[BaseCommondTabbarController alloc]init];
    tabbar.isNativeBar = YES;
    UIApplication *application = [UIApplication sharedApplication];
    UIWindow *window = application.keyWindow;
    window.backgroundColor = [UIColor whiteColor];
    window.rootViewController = tabbar;
    NSMutableDictionary *dic =  [[NSUserDefaults standardUserDefaults] valueForKey:@"tabData"];
    NSMutableArray *itemArray = [dic objectForKey:@"items"];
    tabbar.ViewControllersArray = itemArray;
    NSMutableArray *controllerArray = [NSMutableArray   array];
    for (int i=0; i<itemArray.count; i++) {
        NSDictionary *itemDic = [itemArray objectAtIndex:i];
        NSString *H5_url = [itemDic objectForKey:@"h5_url"];
        NSString *Image_url = [itemDic objectForKey:@"img"];
        NSString *Image_Select_url = [itemDic objectForKey:@"img_selected"];
        NSString *nameString = [itemDic objectForKey:@"name"];
        AfterWebViewController *zwebView = [[AfterWebViewController alloc]init];
        zwebView.webUrl = H5_url;
        BaseCommondNaviController *zwebViewNa = [[BaseCommondNaviController alloc]initWithRootViewController:zwebView];
        zwebViewNa.tabBarItem.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:Image_url]]];
        zwebViewNa.tabBarItem.selectedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:Image_Select_url]]];
        zwebViewNa.tabBarItem.title = nameString;
        zwebViewNa.title = nameString;
        [controllerArray addObject:zwebViewNa];
    }
    tabbar.viewControllers = controllerArray;
}
@end
